package com.epam.android.mailcomponent;

import java.util.List;

import com.epam.android.mailcomponent.contacts.ContactsActivity;
import com.epam.android.mailcomponent.controls.MailView;
import com.epam.android.mailcomponent.controls.util.MailContent;

import com.epam.android.mailcomponent.R;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class TestActivity extends Activity implements OnClickListener {
	
	private MailView mailView;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mailView = (MailView) findViewById(R.id.mail_view);
        mailView.setContactsPickerListener(this);
        MailContent mailContent = mailView.getMailContent(); 
        Log.i(TestActivity.class.toString(), mailContent.toString());
    }

	@Override
	public void onClick(DialogInterface dialog, int which) {
		startActivityForResult(new Intent(this, ContactsActivity.class), MailView.REQUEST_CODE_CONTACTS);
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == MailView.REQUEST_CODE_CONTACTS) {
			if (resultCode == RESULT_OK) {
				List<String> chosenContacts = 
						data.getStringArrayListExtra(ContactsActivity.CONTACTS_LIST_EXTRA_NAME);
				mailView.displayEmails(chosenContacts);
			}
		}
	}
}